<template>
	<view class="main-content">
		<MHeader>{{state.pageName}}</MHeader>
		<scroll-view scroll-y="true" style="height:calc(100% - 80rpx)">
			<view class="line-">
				<text>结算日期：{{moment(state.info.Data.F_QUQY_PZDate).format('YYYY-MM-DD')}}</text>
				<text>{{state.info.Data.BillNo}}</text>
			</view>
			<view class="line-">
				<text class="line-color">养殖利润</text>
				<text class="line-color">回收数量（只）</text>
			</view>
			<view class="line-" style="margin-bottom: 20rpx;">
				<view class="line-txt">{{state.info.Data.F_QUQY_PROFIT}}</view>
				<view class="line-txt">{{state.info.Data.F_QUQY_HSQTY}}</view>
			</view>
			<view class="header-">
				<view class="label">上苗日期</view>
				{{moment(state.info.Data.F_QUQY_SEEDDATE).format('YYYY-MM-DD')}}
			</view>
			<view class="line-info">
				<view class="label">养殖户</view>
				{{state.info.Data.F_QUQY_YZH&&state.info.Data.F_QUQY_YZH?.Name[0]?.Value}}
			</view>
			<view class="line-info">
				<view class="label">养殖批次</view>
				{{state.info.Data.F_QUQY_BREEDBATCH?.Name[0].Value}}
			</view>
			<view class="line-info">
				<view class="label">宰杀日期</view>
				{{moment(state.info.Data.F_QUQY_HSDATE).format('YYYY-MM-DD')}}
			</view>
			<view class="line-info">
				<view class="label">业务员</view>
				{{state.info.Data.F_QUQY_YWY?.Name[0].Value}}
			</view>
			<view class="line-info">
				<view class="label">补贴金额</view>
				{{state.info.Data.F_QUQY_SettleSubEntrySum?.toFixed(2)}}
			</view>
			<view class="line-info">
				<view class="label">保证金</view>
				{{state.info.Data.F_QUQY_BZJPRICE?.toFixed(2)}}
			</view>
			<view class="line-info">
				<view class="label">实付金额</view>
				<view style="color: #f00;font-weight:600">
					{{state.info.Data.F_QUQY_PAYAMOUNT?.toFixed(2)}}
				</view>
			</view>
			<MHeader hidTag>
				<van-icon name="cluster" color="#1989fa" style="margin-right: 10rpx" />
				收入项目明细：{{state.info.Data.FEntitySum}}元
			</MHeader>
			<table>
				<tr>
					<th>只数</th>
					<th>单价</th>
					<th>重量</th>
					<th>金额</th>
				</tr>
				<tr v-for="(item,index) in state.info.Data.QUQY_t_SettleIncomeAEntry" :key="index">
					<td>{{item.F_QUQY_INALLQTY}}</td>
					<td>{{item.FINJSPRICE}}</td>
					<td>{{item.F_QUQY_WEIGHTALL}}</td>
					<td>{{item.F_QUQY_AMOUNTALL}}</td>
				</tr>
			</table>
			<MHeader hidTag>
				<van-icon name="cluster" color="#1989fa" style="margin-right: 10rpx" />
				支出项目明细：{{state.info.Data.F_QUQY_SettleOutEntrySum}}元
			</MHeader>
			<table>
				<tr>
					<th>项目</th>
					<th>类型</th>
					<th>数量</th>
					<th>单价</th>
					<!-- <th>成本金额</th> -->
					<th>支出金额</th>
				</tr>
				<tr v-for="(item,index) in state.info.Data.QUQY_t_SettleOutALLEntry" :key="index">
					<td>{{item.F_QUQY_OUTMATERIALALL?.Name[0].Value}}</td>
					<td>{{item.F_QUQY_ZCTYPEALL}}</td>
					<td>{{item.F_QUQY_OUTQTYALL}}</td>
					<td>{{item.F_QUQY_OUTJSPRICE}}</td>
					<!-- <td>{{item.F_QUQY_OUTCBAMOUNTALL?.toFixed(2)}}</td> -->
					<td>{{item.F_QUQY_BILLALLAMOUNTALL?.toFixed(2)}}</td>
				</tr>
			</table>
			<MHeader hidTag>
				<van-icon name="cluster" color="#1989fa" style="margin-right: 10rpx" />
				合同补贴明细：{{state.info.Data.F_QUQY_SettleSubEntrySum}}元
			</MHeader>
			<table>
				<tr>
					<th>项目</th>
					<th>数量</th>
					<th>单价</th>
					<th>金额</th>
				</tr>
				<tr v-for="(item,index) in state.info.Data.F_QUQY_SettleSubEntry" :key="index">
					<td>{{item.F_QUQY_SUBNAME&&item.F_QUQY_SUBNAME?.FDataValue[0].Value}}</td>
					<td>{{item.F_QUQY_SUBQTY}}</td>
					<td>{{item.F_QUQY_SUBPRICE}}</td>
					<td>{{item.F_QUQY_SUBAMOUNT?.toFixed(2)}}</td>
				</tr>
			</table>
		</scroll-view>
	</view>
	<Loading v-if="state.loading"></Loading>
</template>

<script setup>
	import moment from 'moment'
	import { reactive, ref, } from 'vue'
	import { onLoad } from '@dcloudio/uni-app'
	import kdApis from '/api/modularApi/kdApi.js'
	const state = reactive({
		info: {
			FormId: 'QUQY_Settle',
			Data: {
				Model: {
					TypeName: null
				}
			}
		},
		status: {
			Z: '暂 存',
			A: '保 存',
			B: '审核中',
			C: '已审核',
			D: '重新审核'
		},
		jsStatus: {
			A: '全部结算',
			B: '部分结算'
		},
		loading: true
	})

	const getDetails = (Id) => {
		kdApis.formView({
			formId: 'QUQY_Settle',
			data: { Id }
		}).then(res => {
			if (res) {
				if (!res.FEntity) {
					res.FEntity = []
					res.FEntitySum = 0
				} else {
					res.FEntitySum = res.FEntity.reduce((preV, next) => Number(preV + next.F_QUQY_AMOUNT), 0)
				}
				if (!res.QUQY_t_SettleOutALLEntry) {
					res.QUQY_t_SettleOutALLEntry = []
					res.F_QUQY_SettleOutEntrySum = 0
				} else {
					res.F_QUQY_SettleOutEntrySum = res.QUQY_t_SettleOutALLEntry.reduce((preV, next) => preV + Number(next.F_QUQY_BILLALLAMOUNTALL), 0)
				}
				if (!res.F_QUQY_SettleSubEntry) {
					res.F_QUQY_SettleSubEntry = []
					res.F_QUQY_SettleSubEntrySum = 0
				} else {
					res.F_QUQY_SettleSubEntrySum = res.F_QUQY_SettleSubEntry.reduce((preV, next) => preV + Number(next.F_QUQY_SUBAMOUNT), 0)
				}
				state.info.Data = res
				state.loading = false
			}
		})
	}

	onLoad(async (query) => {
		if (query.Id) {
			state.pageName = "养殖结算单详情"
			getDetails(query.Id)
		}
	})
</script>
<style lang="scss" scoped>
	.line- {
		display: flex;
		align-items: center;
		justify-content: space-between;
		height: 80rpx;
		padding: 0 30rpx;

		.line-color {
			color: #00a851;
		}

		.line-txt {
			font-size: 60rpx;
		}
	}

	.header- {
		display: flex;
		align-items: center;
		height: 80rpx;
		background: #f2fafc;
		padding: 0 30rpx;
		color: #7e7d84;

		.label {
			width: 150rpx;
		}
	}

	.line-info {
		display: flex;
		align-items: center;
		height: 80rpx;
		padding: 0 30rpx;
		color: #7e7d84;

		.label {
			width: 150rpx;
		}
	}

	table {
		width: calc(100% - 60rpx);
		border-collapse: collapse;
		font-size: 14px;
		color: #333;
		margin: 30rpx 30rpx 30rpx 30rpx;
	}

	th,
	td {
		height: 60rpx;
		border: 1px solid #efefef;
		text-align: center;
	}

	th {
		height: 80rpx;
	}
</style>